﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sucdri.Domain.Interface;
using Sucdri.Domain.Model;
using Sucdri.Domain.Repository.DataMapper;
using Sucdri.Infrastructure.Core;
using Sucdri.Infrastructure.Core.DbUtility;

namespace Sucdri.Domain.Repository
{
   /*public abstract class BaseRepository<T> : IRepository<T>
      where T:DomainEntity
   {
      private UnitOfWork _uow = new UnitOfWork();
      //todo: implement UnitOfWork Patten
//      private readonly IList<ScheduledAction<T>> _unitOfWork = new List<ScheduledAction<T>>();
//      private bool _isInTransaction;
//
//      private void ProcessAction(ScheduledAction<T> action)
//      {
//         if (_isInTransaction)
//         {
//            _unitOfWork.Add(action);
//         }
//         else
//         {
//            TransactionManager.BeginTransaction();
//
//            TransactionManager.Commit();
//         }
//      }

      public void Dispose()
      {
         throw new NotImplementedException();
      }

//      public bool IsInTransaction
//      {
//         get { throw new NotImplementedException(); }
//      }
//
//      public void BeginTransaction()
//      {
//         if(_isInTransaction)
//            throw new InvalidOperationException("An Transaction has already exists");
//         _isInTransaction = true;
//         _unitOfWork.Clear();
//      }
//
//      public void Commit()
//      {
//         if(!_isInTransaction)
//            throw new InvalidOperationException("No Transaction exists");
//         //todo: implement Commit a bunch of option
//         _isInTransaction = false;
//         _unitOfWork.Clear();
//      }
//
//      public void RollBack()
//      {
//         if (!_isInTransaction)
//            throw new InvalidOperationException("No Transaction exists");
//         _isInTransaction = false;
//         _unitOfWork.Clear();
//      }

//      protected abstract string GetInsertCommand();
//      protected abstract string GetUpdateCommand();
//      protected abstract string GetDeleteCommand();
//      protected abstract IDictionary<string, object> BuildInsertParameter(DomainEntity entity);
//      protected abstract IDictionary<string, object> BuildUpdateParameter(DomainEntity entity);
//      protected abstract IDictionary<string, object> BuildDeleteParameter(DomainEntity entity);
//      protected readonly DbHelper DbHelper;

      protected BaseRepository()
      {
         //DbHelper = DbFactory.GetDbHelper();
      }

    /*  public void Create(DomainEntity entity)
      {
         Guard.ArgumentNotNull("entity",entity);
         var action = new ScheduledAction(entity, ActionType.Create);
         ProcessActions(action);
      }

      public void Update(DomainEntity entity)
      {
         Guard.ArgumentNotNull("entity", entity);
         var action = new ScheduledAction(entity, ActionType.Update);
         ProcessActions(action);
      }

      public void Delete(DomainEntity entity)
      {
         Guard.ArgumentNotNull("entity", entity);
         var action = new ScheduledAction(entity, ActionType.Delete);
         ProcessActions(action);
      }

      internal void ProcessActions(ScheduledAction action)
      {
         _uow.ScheduledActions.Add(action);
      }

      internal void ExecuteScheduledAction(ScheduledAction action)
      {
         if (action.Target is ProjectMain)
         {
            IDataMapper<ProjectMain> mapper = new ProjectMainDataMapper();
            switch (action.Action)
            {
               case ActionType.Create:
                  mapper.Create(action.Target as ProjectMain);
                  break;
               case ActionType.Update:
                  mapper.Update(action.Target as ProjectMain);
                  break;
               case ActionType.Delete:
                  mapper.Delete(action.Target as ProjectMain);
                  break;
            }
         }
         
      }#1#

      public IList<T> GetAll()
      {
         throw new NotImplementedException();
      }

      public IList<T> GetAll(int index, int size)
      {
         throw new NotImplementedException();
      }

      public int GetCount()
      {
         throw new NotImplementedException();
      }

      public T GetById(int id)
      {
         throw new NotImplementedException();
      }
   }*/
}
